home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #define TRUE 1
- #define FALSE 0
- #define XLIM 600 /* Right hand edge of screen */
- #define YLIM 200 /* Bottom of the screen */
- #define XSC 2 /* X scale factor */
- #define YSC 1 /* Y scale - to adjust for aspect ratio */
- #define YSTEP 30 /* Number of dots between lines of characters */
- FILE *fp;
- struct point
- {
- int x;
- int y;
- };
- struct point home;
- main()
- {
- FILE *fopen();
- int seqno,penup,xloc,ypos,lbound,rbound,xpos,yloc,xp,yp,np;
- int rax,rbx,rcx,rdx;
- np=0; /* We've plotted no points yet */
- penup=TRUE; /* Start with pen off of paper */
- xloc=10; /* Starting position at upper left */
- ypos=25;
- fp=fopen("hershey.dat","r");
- if (fp==NULL) /* Couldn't find the data base? */
- {
- printf("Diskette with HERSHEY.DAT must be in default drive.");
- exit(1);
- }
- initp(); /* Initialize graphics */
- while(fscanf(fp,"%d",&seqno)!=EOF) /* Read and skip sequence number */
- {
- getcolon(); /* Gobble up the colon between coordinate pairs */
- np=0; /* Initialize point count for this character */
- fscanf(fp,"%d%d",&lbound,&rbound); /* Get Left and Right limits */
- getcolon(); /* Eat that colon */
- np++; /* Count number of points */
- lbound*=XSC; /* Scale Left limit to screen size */
- rbound*=XSC; /* Ditto for Right limit */
- xpos=xloc+(rbound-lbound)/2; /* Calculate center of character */
- movit(xpos,ypos); /* Move to center of character */
- penup=TRUE; /* Make sure pen is up */
- while(TRUE)
- {
- if(np>14) /* Only 15 points on a data image */
- {
- np=0; /* Reset point counter */
- getcolon(); /* Eat colon to get to coordinate */
- }
- fscanf(fp,"%d%d",&xp,&yp); /* Read an X,Y pair */
- getcolon();
- np++;
- if(xp==-64 && yp==-64) /* X=-64, Y=-64 is end of character */
- break; /* So, exit from loop */
- if(xp!=-64) /* X=-64 would mean new line segment */
- {
- xp*=XSC; /* Scale coordinates */
- yp*=YSC;
- xp+=xpos; /* Update new X,Y positions */
- yp+=ypos;
- if(penup) /* If pen is UP */
- {
- movit(xp,yp); /* Move to this point */
- penup=FALSE; /* And put pen down */
- }
- else /* Pen is alread down, so */
- drawit(xp,yp); /* Draw to new point */
- }
- else /* This is a new line segment */
- penup=TRUE; /* So, lift the pen */
- }
- xloc+=(rbound-lbound); /* Compute new X location */
- if(xloc>=XLIM) /* Run off right edge of screen ? */
- {
- xloc=10; /* Yes, move back to left edge */
- ypos+=YSTEP; /* And move down one line */
- if(ypos>=YLIM) /* Did we fall off the bottom? */
- {
- scanf("%d",ypos);
- ypos=25; /* Yes, move back to top of screen */
- initp(); /* And clear the screen */
- }
- }
- }
- }
- initp() /* Initialize Graphics and clear screen */
- {
- grinit(2,0,0); /* Hi-res, dummy, dummy */
- }
-
- movit(ax,ay) /* Move to AX, AY */
- int ax,ay;
- {
- home.x=ax; /* Just reset home coordinate */
- home.y=ay;
- return;
- }
- drawit(ax,ay) /* Draw a line between HOME and AX,AY */
- int ax,ay;
- {
- struct point pos;
- pos.x=ax;
- pos.y=ay;
- grline(&home,&pos,1); /* MOVE to HOME position, DRAW to POS */
- home.x=pos.x; /* Update HOME position */
- home.y=pos.y;
- return;
- }
- getcolon() /* Gobble up colons in database */
- {
- while(getc(fp)!=':') /* Read everything up to and including */
- { /* The next colon */
- }
- }
-